package com.restaurant.application.indexes.customerlist.mysql;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.nebutown.base.Unit;
import com.nebutown.description.data.SortSpec;
import com.nebutown.generation.basictype.UID;
import com.nebutown.supporthome.AbstractIndex;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

public class CustomerListImpl extends AbstractIndex<CustomerListCriteria, CustomerListBean> {

    @Override
    public String getTableName() {
        return "" + getConnectionName() + ".CUSTOMERLIST";
    }

    @Override
    public CustomerListBean newBean() {
        return new CustomerListBean();
    }

    @Override
    public CustomerListCriteria newCriteria() {
        return new CustomerListCriteria();
    }

    @Override
    public List<String> getFieldNames() {
        return Lists.newArrayList(
                "customerUid",
                "id",
                "createTime",
                "modifyTime",
                "avatarUrl",
                "nickName",
                "realName",
                "gender",
                "birthday",
                "openId",
                "phone",
                "levelName",
                "level",
                "number",
                "qrCodeUrl",
                "qrCodeUid",
                "usableScores",
                "totalScores",
                "state",
                "address");
    }

    @Override
    public List<String> getDateFields() {
        return Lists.newArrayList(
                "createTime",
                "modifyTime");
    }

    @Override
    public List<String> getDoubleFields() {
        return Lists.newArrayList(
                "");
    }

    @Override
    public Map<String, String> getFieldLabels() {
        return ImmutableMap.<String, String>builder()
                .put("id", "用户id")
                .put("createTime", "创建时间")
                .put("modifyTime", "修改时间")
                .put("avatarUrl", "头像地址")
                .put("nickName", "登陆名称")
                .put("realName", "登陆名称")
                .put("gender", "性别")
                .put("birthday", "生日")
                .put("openId", "openId")
                .put("phone", "手机")
                .put("levelName", "会员等级名称")
                .put("level", "会员等级")
                .put("number", "会员编号")
                .put("qrCodeUrl", "会员二维码地址")
                .put("qrCodeUid", "会员二维码Uid")
                .put("usableScores", "可用积分")
                .put("totalScores", "总积分")
                .put("state", "状态")
                .put("address", "状态")
                .build();
    }

    @Override
    public List<String> getContributors() {
        return Lists.newArrayList(
                "com.restaurant.application.customer.Customer");
    }

    @Override
    public CustomerListBean fakeBean() {
        CustomerListBean bean = new CustomerListBean();

        bean.setCustomerUid(UID.recover("A 7564315054264941085 looooong string"));
        bean.setId("A 8832032702230830241 looooong string");
        bean.setCreateTime(-650446992L);
        bean.setModifyTime(-1190214839L);
        bean.setAvatarUrl("A 8351973854445830355 looooong string");
        bean.setNickName("A 3697897036825264527 looooong string");
        bean.setRealName("A -2638731637841867139 looooong string");
        bean.setGender("A -5568636560888078516 looooong string");
        bean.setBirthday("A -6386270777194232550 looooong string");
        bean.setOpenId("A 8599999055037644288 looooong string");
        bean.setPhone("A -3461483583291982975 looooong string");
        bean.setLevelName("A -5410591659937208643 looooong string");
        bean.setLevel("A 7450251093123828862 looooong string");
        bean.setNumber("A 1053443982925074821 looooong string");
        bean.setQrCodeUrl("A -5006301907095736505 looooong string");
        bean.setQrCodeUid("A 1029380324767800513 looooong string");
        bean.setUsableScores("A -3520733977473107904 looooong string");
        bean.setTotalScores("A 448477751104745810 looooong string");
        bean.setState("A 6866372952259733346 looooong string");
        bean.setAddress("A 4692262015840335309 looooong string");
        return bean;
    }

    @Override
    public String getCreateTableStatement() {
        StringBuilder buf = new StringBuilder();

        buf.append("CREATE TABLE IF NOT EXISTS " + getConnectionName() + ".CUSTOMERLIST (\n");
        buf.append("    RECORD_ID BIGINT AUTO_INCREMENT,\n");
        buf.append("    CUSTOMERUID CHAR(128) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,\n");
        buf.append("    ID VARCHAR(255),\n");
        buf.append("    CREATETIME BIGINT,\n");
        buf.append("    MODIFYTIME BIGINT,\n");
        buf.append("    AVATARURL VARCHAR(255),\n");
        buf.append("    NICKNAME VARCHAR(255),\n");
        buf.append("    REALNAME VARCHAR(255),\n");
        buf.append("    GENDER VARCHAR(255),\n");
        buf.append("    BIRTHDAY VARCHAR(255),\n");
        buf.append("    OPENID VARCHAR(255),\n");
        buf.append("    PHONE VARCHAR(255),\n");
        buf.append("    LEVELNAME VARCHAR(255),\n");
        buf.append("    LEVEL VARCHAR(255),\n");
        buf.append("    NUMBER VARCHAR(255),\n");
        buf.append("    QRCODEURL VARCHAR(255),\n");
        buf.append("    QRCODEUID VARCHAR(255),\n");
        buf.append("    USABLESCORES VARCHAR(255),\n");
        buf.append("    TOTALSCORES VARCHAR(255),\n");
        buf.append("    STATE VARCHAR(255),\n");
        buf.append("    ADDRESS VARCHAR(255),\n");
        buf.append("PRIMARY KEY (RECORD_ID)) CHARACTER SET  = utf8mb4 COLLATE = utf8mb4_bin");
        return buf.toString();
    }

    @Override
    public String getInsertDataStatement(CustomerListBean data) {
        StringBuilder buf = new StringBuilder();

        buf.append("INSERT INTO " + getConnectionName() + ".CUSTOMERLIST (\n    ");
        buf.append("    CUSTOMERUID, ID, CREATETIME, MODIFYTIME, AVATARURL, NICKNAME, REALNAME, GENDER, BIRTHDAY, OPENID, PHONE, LEVELNAME, LEVEL, NUMBER, QRCODEURL, QRCODEUID, USABLESCORES, TOTALSCORES, STATE, ADDRESS");
        buf.append(") VALUES (");
        buf.append("    '" + cut(data.getCustomerUid(), 128) + "', '" + cut(data.getId(), 255) + "', " + data.getCreateTime() + ", " + data.getModifyTime() + ", '" + cut(data.getAvatarUrl(), 255) + "', '" + cut(data.getNickName(), 255) + "', '" + cut(data.getRealName(), 255) + "', '" + cut(data.getGender(), 255) + "', '" + cut(data.getBirthday(), 255) + "', '" + cut(data.getOpenId(), 255) + "', '" + cut(data.getPhone(), 255) + "', '" + cut(data.getLevelName(), 255) + "', '" + cut(data.getLevel(), 255) + "', '" + cut(data.getNumber(), 255) + "', '" + cut(data.getQrCodeUrl(), 255) + "', '" + cut(data.getQrCodeUid(), 255) + "', '" + cut(data.getUsableScores(), 255) + "', '" + cut(data.getTotalScores(), 255) + "', '" + cut(data.getState(), 255) + "', '" + cut(data.getAddress(), 255) + "'");
        buf.append(")");
        return buf.toString();
    }

    @Override
    public String getDeleteRowsStatement(Long rowId) {
        return "DELETE FROM " + getConnectionName() + ".CUSTOMERLIST WHERE  RECORD_ID = " + rowId;
    }

    @Override
    public String getLocalUpdateStatement(CustomerListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".CUSTOMERLIST \n");
        buf.append("   SET ");
        if(data.getCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERUID = '" + cut(data.getCustomerUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getAvatarUrl() != null) {
            buf.append(sep.toString() + "\n      AVATARURL = '" + cut(data.getAvatarUrl(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNickName() != null) {
            buf.append(sep.toString() + "\n      NICKNAME = '" + cut(data.getNickName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRealName() != null) {
            buf.append(sep.toString() + "\n      REALNAME = '" + cut(data.getRealName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getGender() != null) {
            buf.append(sep.toString() + "\n      GENDER = '" + cut(data.getGender(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getBirthday() != null) {
            buf.append(sep.toString() + "\n      BIRTHDAY = '" + cut(data.getBirthday(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getOpenId() != null) {
            buf.append(sep.toString() + "\n      OPENID = '" + cut(data.getOpenId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPhone() != null) {
            buf.append(sep.toString() + "\n      PHONE = '" + cut(data.getPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLevelName() != null) {
            buf.append(sep.toString() + "\n      LEVELNAME = '" + cut(data.getLevelName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLevel() != null) {
            buf.append(sep.toString() + "\n      LEVEL = '" + cut(data.getLevel(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUrl() != null) {
            buf.append(sep.toString() + "\n      QRCODEURL = '" + cut(data.getQrCodeUrl(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUid() != null) {
            buf.append(sep.toString() + "\n      QRCODEUID = '" + cut(data.getQrCodeUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getUsableScores() != null) {
            buf.append(sep.toString() + "\n      USABLESCORES = '" + cut(data.getUsableScores(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getTotalScores() != null) {
            buf.append(sep.toString() + "\n      TOTALSCORES = '" + cut(data.getTotalScores(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getAddress() != null) {
            buf.append(sep.toString() + "\n      ADDRESS = '" + cut(data.getAddress(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE TRUE\n");
        if(data.getCustomerUid() != null) {
            buf.append("    AND CUSTOMERUID = '" + data.getCustomerUid() + "'\n");
            hasData = true;
        }
        if(!hasData) return "";

        return buf.toString();
    }

    @Override
    public String getUpdateByIdStatement(CustomerListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".CUSTOMERLIST \n");
        buf.append("   SET ");
        if(data.getCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERUID = '" + cut(data.getCustomerUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getAvatarUrl() != null) {
            buf.append(sep.toString() + "\n      AVATARURL = '" + cut(data.getAvatarUrl(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNickName() != null) {
            buf.append(sep.toString() + "\n      NICKNAME = '" + cut(data.getNickName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRealName() != null) {
            buf.append(sep.toString() + "\n      REALNAME = '" + cut(data.getRealName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getGender() != null) {
            buf.append(sep.toString() + "\n      GENDER = '" + cut(data.getGender(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getBirthday() != null) {
            buf.append(sep.toString() + "\n      BIRTHDAY = '" + cut(data.getBirthday(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getOpenId() != null) {
            buf.append(sep.toString() + "\n      OPENID = '" + cut(data.getOpenId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPhone() != null) {
            buf.append(sep.toString() + "\n      PHONE = '" + cut(data.getPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLevelName() != null) {
            buf.append(sep.toString() + "\n      LEVELNAME = '" + cut(data.getLevelName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getLevel() != null) {
            buf.append(sep.toString() + "\n      LEVEL = '" + cut(data.getLevel(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUrl() != null) {
            buf.append(sep.toString() + "\n      QRCODEURL = '" + cut(data.getQrCodeUrl(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getQrCodeUid() != null) {
            buf.append(sep.toString() + "\n      QRCODEUID = '" + cut(data.getQrCodeUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getUsableScores() != null) {
            buf.append(sep.toString() + "\n      USABLESCORES = '" + cut(data.getUsableScores(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getTotalScores() != null) {
            buf.append(sep.toString() + "\n      TOTALSCORES = '" + cut(data.getTotalScores(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getAddress() != null) {
            buf.append(sep.toString() + "\n      ADDRESS = '" + cut(data.getAddress(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE RECORD_ID = " + data.getRecordId());
        return buf.toString();
    }

    @Override
    public CustomerListBean extractLine(ResultSet resultSet) throws Exception {
        CustomerListBean result = new CustomerListBean();

        result.setRecordId(resultSet.getLong("RECORD_ID"));
        result.setCustomerUid(UID.recover(resultSet.getString("customerUid")));
        result.setId(resultSet.getString("id"));
        result.setCreateTime(resultSet.getLong("createTime"));
        result.setModifyTime(resultSet.getLong("modifyTime"));
        result.setAvatarUrl(resultSet.getString("avatarUrl"));
        result.setNickName(resultSet.getString("nickName"));
        result.setRealName(resultSet.getString("realName"));
        result.setGender(resultSet.getString("gender"));
        result.setBirthday(resultSet.getString("birthday"));
        result.setOpenId(resultSet.getString("openId"));
        result.setPhone(resultSet.getString("phone"));
        result.setLevelName(resultSet.getString("levelName"));
        result.setLevel(resultSet.getString("level"));
        result.setNumber(resultSet.getString("number"));
        result.setQrCodeUrl(resultSet.getString("qrCodeUrl"));
        result.setQrCodeUid(resultSet.getString("qrCodeUid"));
        result.setUsableScores(resultSet.getString("usableScores"));
        result.setTotalScores(resultSet.getString("totalScores"));
        result.setState(resultSet.getString("state"));
        result.setAddress(resultSet.getString("address"));
        return result;
    }

    @Override
    public String getWherePart(CustomerListCriteria criteria, SortSpec sort) {
        StringBuilder buf = new StringBuilder(" TRUE ");

        criteria.setIdLike(searchString(criteria.getIdLike()));
        criteria.setAvatarUrlLike(searchString(criteria.getAvatarUrlLike()));
        criteria.setNickNameLike(searchString(criteria.getNickNameLike()));
        criteria.setRealNameLike(searchString(criteria.getRealNameLike()));
        criteria.setGenderLike(searchString(criteria.getGenderLike()));
        criteria.setBirthdayLike(searchString(criteria.getBirthdayLike()));
        criteria.setOpenIdLike(searchString(criteria.getOpenIdLike()));
        criteria.setPhoneLike(searchString(criteria.getPhoneLike()));
        criteria.setLevelNameLike(searchString(criteria.getLevelNameLike()));
        criteria.setLevelLike(searchString(criteria.getLevelLike()));
        criteria.setNumberLike(searchString(criteria.getNumberLike()));
        criteria.setQrCodeUrlLike(searchString(criteria.getQrCodeUrlLike()));
        criteria.setQrCodeUidLike(searchString(criteria.getQrCodeUidLike()));
        criteria.setUsableScoresLike(searchString(criteria.getUsableScoresLike()));
        criteria.setTotalScoresLike(searchString(criteria.getTotalScoresLike()));
        criteria.setStateLike(searchString(criteria.getStateLike()));
        criteria.setAddressLike(searchString(criteria.getAddressLike()));

        if(criteria.getRecordId() != null) {
            buf.append("    AND RECORD_ID = " + criteria.getRecordId());
        }
        if(criteria.getCustomerUidEquals() != null) {
            buf.append("    AND CUSTOMERUID = '" + criteria.getCustomerUidEquals() + "'");
        }
        if(criteria.getCustomerUidNotEquals() != null) {
            buf.append("    AND CUSTOMERUID != '" + criteria.getCustomerUidNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdEquals())) {
            buf.append("    AND ID = '" + cut(criteria.getIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdNotEquals())) {
            buf.append("    AND ID != '" + cut(criteria.getIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdLike())) {
            buf.append("    AND ID LIKE '" + cut(criteria.getIdLike()) + "'");
        }
        if(criteria.getCreateTimeUpper() != null) {
            buf.append("    AND CREATETIME <= " + criteria.getCreateTimeUpper());
        }
        if(criteria.getCreateTimeLower() != null) {
            buf.append("    AND CREATETIME >= " + criteria.getCreateTimeLower());
        }
        if(criteria.getCreateTimeEquals() != null) {
            buf.append("    AND CREATETIME = '" + criteria.getCreateTimeEquals() + "'");
        }
        if(criteria.getCreateTimeNotEquals() != null) {
            buf.append("    AND CREATETIME != '" + criteria.getCreateTimeNotEquals() + "'");
        }
        if(criteria.getModifyTimeUpper() != null) {
            buf.append("    AND MODIFYTIME <= " + criteria.getModifyTimeUpper());
        }
        if(criteria.getModifyTimeLower() != null) {
            buf.append("    AND MODIFYTIME >= " + criteria.getModifyTimeLower());
        }
        if(criteria.getModifyTimeEquals() != null) {
            buf.append("    AND MODIFYTIME = '" + criteria.getModifyTimeEquals() + "'");
        }
        if(criteria.getModifyTimeNotEquals() != null) {
            buf.append("    AND MODIFYTIME != '" + criteria.getModifyTimeNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAvatarUrlEquals())) {
            buf.append("    AND AVATARURL = '" + cut(criteria.getAvatarUrlEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAvatarUrlNotEquals())) {
            buf.append("    AND AVATARURL != '" + cut(criteria.getAvatarUrlNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAvatarUrlLike())) {
            buf.append("    AND AVATARURL LIKE '" + cut(criteria.getAvatarUrlLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNickNameEquals())) {
            buf.append("    AND NICKNAME = '" + cut(criteria.getNickNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNickNameNotEquals())) {
            buf.append("    AND NICKNAME != '" + cut(criteria.getNickNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNickNameLike())) {
            buf.append("    AND NICKNAME LIKE '" + cut(criteria.getNickNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRealNameEquals())) {
            buf.append("    AND REALNAME = '" + cut(criteria.getRealNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRealNameNotEquals())) {
            buf.append("    AND REALNAME != '" + cut(criteria.getRealNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRealNameLike())) {
            buf.append("    AND REALNAME LIKE '" + cut(criteria.getRealNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getGenderEquals())) {
            buf.append("    AND GENDER = '" + cut(criteria.getGenderEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getGenderNotEquals())) {
            buf.append("    AND GENDER != '" + cut(criteria.getGenderNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getGenderLike())) {
            buf.append("    AND GENDER LIKE '" + cut(criteria.getGenderLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getBirthdayEquals())) {
            buf.append("    AND BIRTHDAY = '" + cut(criteria.getBirthdayEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getBirthdayNotEquals())) {
            buf.append("    AND BIRTHDAY != '" + cut(criteria.getBirthdayNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getBirthdayLike())) {
            buf.append("    AND BIRTHDAY LIKE '" + cut(criteria.getBirthdayLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getOpenIdEquals())) {
            buf.append("    AND OPENID = '" + cut(criteria.getOpenIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getOpenIdNotEquals())) {
            buf.append("    AND OPENID != '" + cut(criteria.getOpenIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getOpenIdLike())) {
            buf.append("    AND OPENID LIKE '" + cut(criteria.getOpenIdLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneEquals())) {
            buf.append("    AND PHONE = '" + cut(criteria.getPhoneEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneNotEquals())) {
            buf.append("    AND PHONE != '" + cut(criteria.getPhoneNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneLike())) {
            buf.append("    AND PHONE LIKE '" + cut(criteria.getPhoneLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLevelNameEquals())) {
            buf.append("    AND LEVELNAME = '" + cut(criteria.getLevelNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLevelNameNotEquals())) {
            buf.append("    AND LEVELNAME != '" + cut(criteria.getLevelNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLevelNameLike())) {
            buf.append("    AND LEVELNAME LIKE '" + cut(criteria.getLevelNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLevelEquals())) {
            buf.append("    AND LEVEL = '" + cut(criteria.getLevelEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLevelNotEquals())) {
            buf.append("    AND LEVEL != '" + cut(criteria.getLevelNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getLevelLike())) {
            buf.append("    AND LEVEL LIKE '" + cut(criteria.getLevelLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberEquals())) {
            buf.append("    AND NUMBER = '" + cut(criteria.getNumberEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberNotEquals())) {
            buf.append("    AND NUMBER != '" + cut(criteria.getNumberNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberLike())) {
            buf.append("    AND NUMBER LIKE '" + cut(criteria.getNumberLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUrlEquals())) {
            buf.append("    AND QRCODEURL = '" + cut(criteria.getQrCodeUrlEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUrlNotEquals())) {
            buf.append("    AND QRCODEURL != '" + cut(criteria.getQrCodeUrlNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUrlLike())) {
            buf.append("    AND QRCODEURL LIKE '" + cut(criteria.getQrCodeUrlLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUidEquals())) {
            buf.append("    AND QRCODEUID = '" + cut(criteria.getQrCodeUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUidNotEquals())) {
            buf.append("    AND QRCODEUID != '" + cut(criteria.getQrCodeUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getQrCodeUidLike())) {
            buf.append("    AND QRCODEUID LIKE '" + cut(criteria.getQrCodeUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getUsableScoresEquals())) {
            buf.append("    AND USABLESCORES = '" + cut(criteria.getUsableScoresEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getUsableScoresNotEquals())) {
            buf.append("    AND USABLESCORES != '" + cut(criteria.getUsableScoresNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getUsableScoresLike())) {
            buf.append("    AND USABLESCORES LIKE '" + cut(criteria.getUsableScoresLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTotalScoresEquals())) {
            buf.append("    AND TOTALSCORES = '" + cut(criteria.getTotalScoresEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTotalScoresNotEquals())) {
            buf.append("    AND TOTALSCORES != '" + cut(criteria.getTotalScoresNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getTotalScoresLike())) {
            buf.append("    AND TOTALSCORES LIKE '" + cut(criteria.getTotalScoresLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateEquals())) {
            buf.append("    AND STATE = '" + cut(criteria.getStateEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateNotEquals())) {
            buf.append("    AND STATE != '" + cut(criteria.getStateNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateLike())) {
            buf.append("    AND STATE LIKE '" + cut(criteria.getStateLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAddressEquals())) {
            buf.append("    AND ADDRESS = '" + cut(criteria.getAddressEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAddressNotEquals())) {
            buf.append("    AND ADDRESS != '" + cut(criteria.getAddressNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getAddressLike())) {
            buf.append("    AND ADDRESS LIKE '" + cut(criteria.getAddressLike()) + "'");
        }
        if(sort != null && sort.getColumns().size() > 0) {
            buf.append(" ORDER BY ");
            sort.getColumns().forEach(c->buf.append(c.getColumnName().toUpperCase())
                .append(" ").append((c.getAscending() != null && c.getAscending()) ? "ASC" : "DESC")
                .append(", "));
            buf.append("RECORD_ID ASC");
        }
        return buf.toString();
    }

    @Override
    public <T extends Unit > String getUpdateStatement(T source) {
        CustomerListBean data = null;

        if(source instanceof com.restaurant.application.indexes.customerlist.mysql.CustomerListFromcustomerUidIF) {
            data = new CustomerListBean();
             ((com.restaurant.application.indexes.customerlist.mysql.CustomerListFromcustomerUidIF)source).getCustomerUidDataForCustomerList(data);
        }

        return data == null ? null: getLocalUpdateStatement(data);
    }
}
